package com.gh.netty.server.handler;


import org.apache.log4j.Logger;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.util.CharsetUtil;

/**
 * @author hugx
 * @create 2018-09-29 16:33
 */
public class MyReadHandler implements ChannelInboundHandler {
    private static final Logger log=Logger.getLogger(MyReadHandler.class);


    @Override
    public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
        log.info("----- channelRegistered ");
    }

    @Override
    public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
        log.info("----- channelUnregistered ");
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        log.info("----- channelActive ");
    }

    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        log.info("----- channelInactive ");
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ByteBuf bb= (ByteBuf) msg;
        log.info("----- channelRead  , "+bb.toString(CharsetUtil.UTF_8));

    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        log.info("----- channelReadComplete ");
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        log.info("----- userEventTriggered ");
    }

    @Override
    public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
        log.info("----- channelWritabilityChanged ");
    }

    @Override
    public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
        log.info("----- handlerAdded ");
    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
        log.info("----- handlerRemoved ");
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        log.info("----- exceptionCaught ");
    }
}
